package com.ma.filter;

import com.ma.utils.Constant;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class SysFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        HttpServletRequest request_1 = (HttpServletRequest) servletRequest;
        HttpServletResponse response_1 = (HttpServletResponse) servletResponse;

        Object attribute = request_1.getSession().getAttribute(Constant.User_SESSION);
        if (attribute==null){
            response_1.sendRedirect("/error.jsp");
        }


        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
